home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / PINLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  3.9 KB  |  206 lines

  1. // the implementation of class PIN_LIST
  2. // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include <algorithm>
  5. #include <string.h>
  6. #include "../kbandef.h"
  7. #include "file.h"
  8.  
  9. #include "pinlist.h"
  10.  
  11. XY PIN_LIST::get_max() const
  12. {
  13.   XY ac_max(X_MIN, Y_MIN);
  14.   iterator i;
  15.   TRAVERSE(*this, i) {
  16.     ac_max = ::get_max(ac_max, i->get_max());
  17.   }
  18.   return ac_max;
  19. }
  20.  
  21. XY PIN_LIST::get_min() const
  22. {
  23.   XY ac_min(X_MAX, Y_MAX);
  24.   iterator i;
  25.   TRAVERSE(*this, i) {
  26.     ac_min = ::get_min(ac_min, i->get_min());
  27.   }
  28.   return ac_min;
  29. }
  30.  
  31. void PIN_LIST::shift(const XY& ac_dif, PIN_LIST& target) const
  32. {
  33.   iterator i;
  34.   TRAVERSE(*this, i) {
  35.     target.push_back(i->shift(ac_dif));
  36.   }
  37. }
  38.  
  39. int PIN_LIST::save(FILE_NEW& fp) const
  40. {
  41.   FILE_VERSION fver;
  42.   fp.printf("%s\n", fver.get_version_str(FILE_VERSION::VERSION_200B0));
  43.  
  44.   iterator i;
  45.   TRAVERSE(*this, i) {
  46.     i->save_200b0(fp);
  47.   }
  48.  
  49.   fp.puts("end\n");
  50.   return true;
  51. }
  52.  
  53. uint PIN_LIST::load_get_version(FILE_NEW& fp) const
  54. {
  55.   FILE_VERSION fver;
  56.   char str[1024];
  57.   fp.gets_wo_return(str, 1024);
  58.   return fver.get_version_no(str);
  59. }
  60.  
  61. PIN_LIST::LOAD_FUNC_INFO PIN_LIST::load_func_table[] = {
  62.   {FILE_VERSION::VERSION_200A8  , &PIN_ELEMENT::load_200a8},
  63.   {FILE_VERSION::VERSION_200B0  , &PIN_ELEMENT::load_200b0},
  64.   {FILE_VERSION::VERSION_UNKNOWN, NULL                    }
  65. };
  66.  
  67. PIN_LIST::LOAD_FUNC PIN_LIST::get_load_func(uint version) const
  68. {
  69.   uint sentinel = FILE_VERSION::VERSION_UNKNOWN;
  70.   uint index = search_info_table(load_func_table, sentinel, version);
  71.   return load_func_table[index].func;
  72. }
  73.  
  74. int PIN_LIST::load_primitive_170(FILE_NEW& fp)
  75. {
  76.   for(;;) {
  77.     PIN_ELEMENT element;
  78.     char str[1024];
  79.     fp.gets_wo_return(str, 1024);
  80.     if(!strcmp(str, "end")) {
  81.       break;
  82.     }
  83.     element.load_primitive_170(str);
  84.     push_back(element);
  85.   }
  86.   return true;
  87. }
  88.  
  89. int PIN_LIST::load_component_170(FILE_NEW& fp)
  90. {
  91.   for(;;) {
  92.     PIN_ELEMENT element;
  93.     char str[1024];
  94.     fp.gets_wo_return(str, 1024);
  95.     if(!strcmp(str, "end")) {
  96.       break;
  97.     }
  98.     element.load_component_170(str);
  99.     push_back(element);
  100.   }
  101.   return true;
  102. }
  103.  
  104. int PIN_LIST::load(FILE_NEW& fp)
  105. {
  106.   int retval;
  107.   uint version = load_get_version(fp);
  108.   LOAD_FUNC load_func = get_load_func(version);
  109.   if(load_func != NULL) {
  110.     clear();
  111.     for(;;) {
  112.       PIN_ELEMENT element;
  113.       char str[1024];
  114.       fp.gets_wo_return(str, 1024);
  115.       if(!strcmp(str, "end")) {
  116.         break;
  117.       }
  118.       (element.*load_func)(str);
  119.       push_back(element);
  120.     }
  121.     retval = true;
  122.   } else {
  123.     retval = false;
  124.   }
  125.   return retval;
  126. }
  127.  
  128. void PIN_LIST::unselect()
  129. {
  130.   iterator i;
  131.   TRAVERSE(*this, i) {
  132.     i->unselect();
  133.   }
  134. }
  135.  
  136. void PIN_LIST::select_items_in_block(const XY& ac1, const XY& ac2)
  137. {
  138.   iterator i;
  139.   TRAVERSE(*this, i) {
  140.     if(i->is_in_block(ac1, ac2)) {
  141.       i->select();
  142.     }
  143.   }
  144. }
  145.  
  146. void PIN_LIST::collect_selected_items(PIN_LIST& dst) const
  147. {
  148.   iterator i;
  149.   TRAVERSE(*this, i) {
  150.     if(i->is_selected()) {
  151.       dst.push_back(*i);
  152.     }
  153.   }
  154. }
  155.  
  156. void PIN_LIST::remove_selected_items()
  157. {
  158.   iterator i;
  159.   TRAVERSE(*this, i) {
  160.     if(i->is_selected()) {
  161.       iterator current_i = i--;
  162.       erase(current_i);
  163.     }
  164.   }
  165. }
  166.  
  167. void PIN_LIST::collect_aperture(APT_TABLE& apt_table) const
  168. {
  169.   iterator i;
  170.   TRAVERSE(*this, i) {
  171.     const APERTURE& apt = i->apt();
  172.     if(!apt_table.is_included(apt)) {
  173.       apt_table.push_back(apt);
  174.     }
  175.   }
  176. }
  177.  
  178. PIN_ELEMENT* PIN_LIST::search(const XY& ac)
  179. {
  180.   PIN_ELEMENT* p = NULL;
  181.   iterator i;
  182.   TRAVERSE(*this, i) {
  183.     if(i->is_inside(ac)) {
  184.       p = &*i;
  185.       break;
  186.     }
  187.   }
  188.   return p;
  189. }
  190.  
  191. void PIN_LIST::rotate_90()
  192. {
  193.   iterator i;
  194.   TRAVERSE(*this, i) {
  195.     i->rotate_90();
  196.   }
  197. }
  198.  
  199. void PIN_LIST::limit_drill_size(uint drill)
  200. {
  201.   iterator i;
  202.   TRAVERSE(*this, i) {
  203.     i->limit_drill_size(drill);
  204.   }
  205. }
  206.